<div class="container">
	<form class="form-horizontal" role="form" method="post" enctype="multipart/form-data" action="<?= site_url() ?>work_facility/insert_cp"> 
	<div class="col-md-offset-1">
		<div class="col-md-11">
			<div class="panel panel-default">
				<div class="panel-heading">
					<h4 class="panel-title"><b class="caret"></b><b> Request By</b></h4>
				</div>
				<div class="panel-body">
					<div class="col-xs-12 col-sm-6 col-md-6">
						<div class="form-group">
							<label class="col-md-4"><p class="text-center">Status</p></label>
							<div class="col-md-5">
								<select id="UserType" name="UserType" onchange="change_status(this);" class="form-control input-sm">
									<option value="Telkomsel">Telkomsel</option>
									<option value="Vendor">Vendor</option>								
								</select>
							</div>
						</div>
						<div class="form-group">
							<label class="col-md-4"><p class="text-center">Name<span style="color:red;">*</span></p></label>
							<div class="col-md-7"><input type="text" value="" id="r_name" name="r_name" class="select2 form-control input-sm">
							<input type="hidden" value="" id="r_nama" name="r_nama" class="select2 form-control input-sm" readonly="true"/></div>
						</div>
						<div class="form-group">
							<label class="col-md-4"><p class="text-center">ID Number</p></label>
							<div class="col-md-4"><input type="text" value="" id="r_id" name="r_id" class="form-control input-sm" readonly ></div>
						</div>						
					</div>
					<div class="col-xs-12 col-sm-6 col-md-6">
						<div class="form-group">
							<label class="col-md-4"><p class="text-center">Manager</p></label>
							<div class="col-md-7"><input type="text" value="" id="r_mgr" name="r_mgr" class="form-control input-sm" readonly >
							<input type="hidden" value="" id="r_mgrid" name="r_mgrid" class="form-control input-sm" readonly="true"/></div>
						</div>			
						<div class="form-group" id="r_Dept" name="r_Dept" style="visibility:visible;">
							<label class="col-md-4"><p class="text-center">Departement</p></label>
							<div class="col-md-7"><input type="text" value="" id="r_dept" name="r_dept" class="form-control input-sm" readonly ></div>
						</div>
						<div class="form-group" id="r_JobPos" name="r_JobPos" style="visibility:visible;">
							<label class="col-md-4"><p class="text-center">Job Position</p></label>
							<div class="col-md-8"><input type="text" value="" id="r_job" name="r_job" class="form-control input-sm" readonly ></div>
						</div>
					</div>
				</div>
			</div>
			<div class="panel panel-default">
				<div class="panel-heading"><h4 class="panel-title"><b class="caret"></b><b> Form</b></h4></div>
				<div class="panel-body">
					<div class="col-xs-12 col-sm-6 col-md-6">				
						<div class="form-group">
							<label class="control-label col-md-4">ID Card</label>
							<div class="col-md-4">
								<select name="pCardFisik" class="form-control input-sm">
									<option value="0">No</option>
									<option value="1">Yes</option>
								</select>
							</div>
						</div>
						<div class="form-group">
							<label class="control-label col-md-4">Fixed Phone<span style="color:red;">*</span></label>
							<div class="col-md-5">
								<select name="pPhoneFisik" id="pPhoneFisik" class="form-control input-sm">
									<option value="">-- select --</option>
									<option value="Analog">Analog</option>
									<option value="Digital">Digital</option>
								</select>
							</div>
						</div>
						<!--div class="form-group" id="Doc_Ref" style="visibility:hidden;">
							<label class="control-label col-md-5">Doc. Reference</label>
							<div class="col-md-7"><input type="text" value="" name="pCtrlSik" class="form-control input-sm" readonly ></div>
						</div-->						
						<div class="form-group" id="Doc_Ref" style="visibility:hidden;">
							<label class="control-label col-md-4">Ref. Doc.<span style="color:red;">*</span></label>
    						<div class="col-md-5">
                            <select name="pCtrlSik" id="pCtrlSik" class="form-control select2"  style="width:230px;">
								<option value="">-- select --</option>
									<?php
									foreach($getReference as $ref){
									?>
									<option value="<?php echo $ref['SIK_ID']?>" <?php if($vCtrlSikNo==$ref['SIK_ID']){?> selected="" <?php } ?> >
										<?php echo $ref['SIK_ID'];?>
								</option>
									<?php
									}
									?>
                            </select>
                            </div>
						</div>						
						<div class="well well-sm" style="text-align:left">
							<div class="form-group">
								<label class="control-label col-md-2">Facility</label>
								<div class="col-md-10">
									<div class="checkbox">
										<ul class="headerGroup">
											<li>			
												<input type="checkbox" value="Y" id="rFloor" name="rFloor" checked><label>Floor Access</label>
												<ul class="group">
													<?php $i=0;
													foreach($floor_active as $row){
														$pValue = $row['MST_FLOOR_DESC'];
													?>
														<li>
															<input type="checkbox" id="cekFloor<?php echo $i;?>" name="cekFloor<?php echo $i;?>" value="Y" checked><label><?php echo $pValue;?></label>
															<input type="hidden" id="pFloor<?php echo $i;?>" name="pFloor<?php echo $i;?>" value="<?php echo $pValue;?>"/>
														</li>
													<?php 
														$i++;
													} ?>
													<input type="hidden" id="TotFloorRow" name="TotFloorRow" value="<?php echo $i;?>"/>
												</ul>
											</li>
										</ul>
									</div>
									<div class="checkbox">
										<ul class="headerGroup">
											<li>				
												<input type="checkbox" value="Y" id="rLine" name="rLine" checked><label>Telephone Line</label>
												<ul class="group">
													<li><label>SLI</label><input id="ceksli" name="ceksli" type="checkbox" value="Y" checked></li>
													<li><label>SLJJ</label><input id="ceksljj" name="ceksljj" type="checkbox" value="Y" checked></li>
													<li><label>LOCAL</label><input id="ceklocal" name="ceklocal" type="checkbox" value="Y" checked></li>
												</ul>
											</li>
										</ul>
									</div>
								</div>
							</div>
						</div>
					</div>
					<div class="col-xs-12 col-sm-5 col-md-6">
						<div class="form-group">
							<label class="control-label col-md-4">Order Date</label>
							<div class="col-md-6">
								<div class="input-group">
									<span class="input-group-addon"><small>From</small></span>
									<input type="text" class="form-control input-sm" autocomplete="off" id="G_Date1" name="G_Date1" value="<?php echo $dtNow?>">
								</div>
							</div>
						</div>
						<div class="form-group">
							<label class="control-label col-md-4"></label>
							<div class="col-md-6">
								<div class="input-group">
									<span class="input-group-addon"><small>To</small></span>
									<input type="text" class="form-control input-sm" autocomplete="off" id="G_Date2" name="G_Date2" value="<?php echo $dtNow?>">
								</div>
							</div>
						</div>			
						<div class="form-group">
							<label class="control-label col-md-4">Request Date</label>
							<div class="col-md-5"><input id="pCtrlDate" name="pCtrlDate" type="text" value="<?php echo $dtNow;?>" class="form-control input-sm" readonly /></div>
						</div>
						<div class="form-group">
							<label class="control-label col-md-4">Description<span style="color:red;">*</span></label>
							<div class="col-md-6">
								<textarea id="pCtrlDesc" name="pCtrlDesc" class="form-control input-sm" style="min-width:190px;max-width:200px;min-height:100px;max-height:200px;"></textarea>
							</div>
						</div>
						<div class="form-group">
							<label class="control-label col-md-4">Upload Photo</label>
							<div class="col-md-5">
								<input type="file" id="file" name="file" class="control-label"> <? //onchange="myFunction()" ?>
								<!--input type="hidden" class="form-control input-sm" id="nama_file" value="" -->
							</div>
						</div>
					</div>
					
					<script type="text/javascript">
					function myFunction()
					{
						/*
						var x = document.getElementById("file");
						var y = document.getElementById("nama_file");
						y.value = x.value;
						*/
					}
					</script>
					
					<div class="col-md-11">
						<div class="form-group">
							<label class="col-md-13" style="color:red">Order harus mendapatkan persetujuan sesuai KD 043/2004 tentang fasilitas telp dinas karyawan.</label>
						</div>
						<div class="form-group" style="text-align:center">
							<input type="submit" value="Save This Form" name="submit" onclick="return cekDulu(this);" class="btn btn-md btn-success" />
							<!--button type="button" class="btn btn-success btn-md" onclick="cekDulu()">Save This Form</button-->
						</div>
					</div>
				</div>
			</div>
		</div>
	</div>
	</form>
</div>

<script type="text/javascript">
	
	function change_status(elm) 
	{
		var v = document.getElementById('r_Dept');
		var w = document.getElementById('r_JobPos');
		var x = document.getElementById('Doc_Ref');
		/*
		var a = document.getElementById('r_id');
		var b = document.getElementById('r_name');
		var c = document.getElementById('r_nama');
		var d = document.getElementById('r_mgr');
		var e = document.getElementById('r_mgrid');		
		var f = document.getElementById('r_dept');	
		var g = document.getElementById('r_job');
		*/		
		if (elm.value=='Vendor') 
		{
			v.style.visibility = 'hidden';
			w.style.visibility = 'hidden';
			x.style.visibility = 'visible';
			/*
			a.value = '';
			b.value = '';
			c.value = '';
			d.value = '';
			e.value = '';
			f.value = '';
			g.value = '';
			*/
		} 
		else 
		{
			v.style.visibility = 'visible';
			w.style.visibility = 'visible';		
			x.style.visibility = 'hidden';	
		}
	}
	
	$('#pCtrlDate').datetimepicker({
		scrollInput:false,
		closeOnDateSelect:true,
		datepicker:true,
		timepicker:false,
		format:'d/m/Y',
		minDate:'-1970/01/01',
		onGenerate:function( ct ){$(this).find('.xdsoft_date.xdsoft_weekend').addClass('xdsoft_disabled');}
	});
	
	function cekDulu(elm)
	{
		var frm = elm.form;
		var reTgl = /^(\d{1,2})\/(\d{1,2})\/(\d{4})$/;
		var reJam = /^\d{1,2}$/;
		var x = document.getElementById('Doc_Ref');
		
		$r_name = $('#r_name').val();
		if ($r_name==""){alert('Requestor tidak boleh kosong!'); document.getElementById('r_name').focus(); eRRor='1'; return false;}
		
		$pPhoneFisik = $('#pPhoneFisik').val();
		if ($pPhoneFisik==""){alert('Fixed Phone tidak boleh kosong!'); document.getElementById('pPhoneFisik').focus(); eRRor='1'; return false;}

		if(x.style.visibility=='visible'){	
			$pCtrlSik = $('#pCtrlSik').val();
			if ($pCtrlSik==""){alert('Referensi Dokumen tidak boleh kosong!'); document.getElementById('pCtrlSik').focus(); eRRor='1'; return false;}
		}
		
		//$pCtrlDesc = $('#pCtrlDesc').val();
		//if ($pCtrlDesc==""){alert('Description tidak boleh kosong!'); document.getElementById('pCtrlDesc').focus(); eRRor='1'; return false;}
		
		if (!frm.elements['G_Date1'].value.match(reTgl)||!frm.elements['G_Date2'].value.match(reTgl)) {
			alert('Tanggal harus diisi (Format: dd/mm/yyyy)');
			return false;
		} else {
			var a = frm.elements['G_Date1'].value.match(reTgl);
			var b = frm.elements['G_Date2'].value.match(reTgl);
			var sTime = a[3] + a[2] + a[1];
			var eTime = b[3] + b[2] + b[1];
			if (sTime >= eTime) {
				alert('Tanggal akhir harus lebih besar dari tanggal awal (Format: dd/mm/yyyy)');
				frm.elements['G_Date2'].focus();
				return false;
			}
		}
		if (frm.elements['pCtrlDesc'].value.length==0) {
			alert('Description tidak boleh kosong!');
			frm.elements['pCtrlDesc'].focus();
			return false;
		}
				
	}

</script>
